home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / scrnsav2.zip / SCRNSAV2.ASM < prev    next >
Assembly Source File  |  1988-09-01  |  27KB  |  735 lines

  1.         page    ,132
  2.         title   scrnsav2 : Screen Saver for PS/2
  3. ;
  4. ;  Copyright (c) 1988 Alan Ballard
  5. ;
  6. ;  This program is a TSR (Terminate and Stay Resident) utility
  7. ;  "screen saver".  It turns off the video after a specified period
  8. ;  of inactivity (no keyboard or mouse action).  Touching the keyboard or
  9. ;  the mouse will reactivate the screen.
  10. ;
  11. ;  A VGA monitor and the PS/2 extended bios are required.
  12. ;
  13. ;  The program stays resident only the first time it is run.  It may be reexecuted
  14. ;  to disable blanking or to change the interval.
  15. ;
  16. ;  Options are:
  17. ;    integer      - blanking time in minutes (default 5 minutes)
  18. ;    \d           - disable blanking
  19. ;    \e           - enable blanking (default)
  20. ;    \m integer   - set the "multiplex number" to use for communicating
  21. ;                   with the loaded version.
  22. ;
  23.  
  24. ;  Interrupt numbers
  25. Keyboard@ equ   09h
  26. Video_Io@ equ   10h
  27. System_Services@ equ 15h
  28. Timer@  equ     1ch
  29. Dos@    equ     21h
  30. Multiplex@ equ  2fh
  31. Mouse@  equ     74h
  32.  
  33. ; Video I/O function numbers
  34. Read_Display_Combination_Code equ 1a00h
  35.  
  36. ; System services function numbers
  37. Keyboard_Intercept equ 4fh
  38.  
  39. ; Multiplex function numbers
  40. Get_Installed_State equ 0
  41.  
  42. ; Scrnsav2 multiplex functions
  43. Scrnsav_Multiplex_Number equ 150       ; random choice
  44. Scrnsav_Disable equ     10h
  45. Scrnsav_Enable  equ     11h
  46. Scrnsav_Set_Interval equ 12h
  47.  
  48. ; DOS function numbers
  49. Print_String equ 09h
  50. Print_Char   equ 02h
  51. Set_Int equ     25h
  52. Get_Int equ     35h
  53. TSR     equ     31h
  54. Terminate equ   4ch
  55.  
  56. ; Miscellaneous constants
  57. Ticks_Per_Minute equ 1092               ; 60*18.2
  58. Default_Time equ 5                      ; five minute default
  59. Max_Time     equ 30                     ; 30 minute maximum (30*1092=32760)
  60.  
  61. Cr      equ     0dh
  62. Lf      equ     0ah
  63.  
  64. True    equ     0ffh
  65. False   equ     00h
  66.  
  67. ; VGA adaptor constants
  68. SAR     equ     03c4h                   ; Sequencer Address Register
  69. SDR     equ     03c5h                   ; Sequencer Data Register
  70. Clocking_Mode_Index equ 01              ; SAR index for clocking mode reg
  71. Screen_Mask equ 20h                     ; Mask for screen off bit.
  72.  
  73. Scrnsav2 segment para 'code'
  74.         assume  cs:Scrnsav2,ds:nothing,es:nothing
  75. ;
  76. ;  Overlay permanent data on PSP.
  77. ;
  78.         org     05ch                    ; not supposed to change anything before this
  79. Old_Mouse dd    ?                       ; save old int 74 (mouse)
  80. Old_Timer dd    ?                       ; save old timer tick
  81. Old_Ss    dd    ?                       ; save old system services
  82. Old_Multiplex dd ?                      ; save old multiplex
  83. ;
  84. Idle_Count dw   ?                       ; Ticks till we shutdown
  85. Idle_Max   dw   ?                       ; Initial ticks
  86.  
  87. Save_Reg   db   ?                       ; Place to save CRT register value
  88. Multiplex_No db  ?                       ; Multiplex number we're using
  89. Disabled   db   ?                       ; enable/disable flag
  90.  
  91. ;
  92. ; Define command line in PSP...
  93. ;
  94.         org     080h
  95. Cmdline label   byte
  96.         page
  97. ;  Code starts at offset 0100h for COM file.
  98.         org     0100h                   ; beginning for .com programs
  99. Start:  jmp     Initialize              ; initialization code is at end.
  100.  
  101. ;
  102. ; int 15 (system services) enters here.  Checks for keyboard intercept
  103. ; which shows some activity.  Passed on to old interrupt routine in all
  104. ; cases.
  105. ;
  106. System_Services proc far
  107.         cmp     ah,Keyboard_Intercept
  108.         jne     NotKey
  109.         call    Action                  ; record something happenned
  110. NotKey: jmp     Old_Ss                  ; pass it on to old routine
  111. System_Services endp
  112.  
  113. ;
  114. ; int 74h (mouse) enters here.  This also shows there is user activity.
  115. ;
  116. Mouse   proc   far
  117.         call    Action                  ; record something happenned
  118.         jmp     Old_Mouse               ; pass it on
  119. Mouse   endp
  120.  
  121. ;
  122. ;  Common processing for keyboard and mouse action.
  123. ;  Reset timeout interval; turn screen back on if it was off.
  124. ;
  125. Action  proc    near
  126.         push    ax                      ; save a register
  127.         cmp     Idle_Count,0            ; have we reached zero
  128.         jne     Reset                   ; no, just reset count
  129.  
  130. ;  Count had reached zero, so we would have disabled the screen.
  131. ;  Need to turn it back on here.
  132.         push    dx
  133.         mov     dx,SAR                  ; Get the current SDR index
  134.         in      al,dx                   ; ... value and save it
  135.         push    ax                      ; ...
  136.         mov     al,Clocking_Mode_Index  ; Then point it to clocking mode
  137.         out     dx,al                   ; ... register.
  138.         mov     dx,SDR                  ; Set the clocking mode register
  139.         mov     al,Save_Reg             ; ... back to what it was
  140.         out     dx,al
  141.         mov     dx,SAR                  ; Reset SAR to what it was
  142.         pop     ax                      ; ...
  143.         out     dx,al                   ; ...
  144.         pop     dx
  145.  
  146. Reset:  mov     ax,Idle_Max             ; reset count to max
  147.         mov     Idle_Count,ax           ; ...
  148.  
  149.         pop     ax                      ; restore
  150.         ret                             ; return
  151.  
  152. Action  endp
  153.  
  154. ;
  155. ; int 1ch (timer tick) enters here. If blanking enabled, decrement count
  156. ; and see if time to blank screen.
  157. ;
  158. Timer   proc    far
  159.  
  160.         cmp     Disabled,True           ; are we active?
  161.         je      Done                    ; no, quit
  162.         cmp     Idle_Count,0            ; already turned off?
  163.         je      Done                    ; ok, nothing to do
  164.  
  165.         dec     Idle_Count              ; subtract one...
  166.         jnz     Done                    ; quit if still nonzero
  167.  
  168. ; Count has reached zero.  Turn off the display.
  169.         push    dx
  170.         push    ax
  171.         mov     dx,SAR                  ; Get the current SDR index
  172.         in      al,dx                   ; ... value and save it
  173.         push    ax                      ; ...
  174.         mov     al,Clocking_Mode_Index  ; Then point it to clocking mode
  175.         out     dx,al                   ; ... register.
  176.         mov     dx,SDR                  ; Get the clocking mode register
  177.         in      al,dx                   ; ...
  178.         mov     Save_Reg,al             ; Save it away for later
  179.         or      al,Screen_Mask          ; set the video off bit
  180.         out     dx,al                   ; ...
  181.         mov     dx,SAR                  ; Reset SAR to what it was
  182.         pop     ax                      ; ...
  183.         out     dx,al                   ; ...
  184.         pop     ax
  185.         pop     dx
  186.  
  187. Done:   jmp     Old_Timer               ; continue with other int routine.
  188. Timer   endp
  189.         page
  190. ;
  191. ; int 2fh (Multiplex) enters here.  This is used for communication from
  192. ; later runs of Scrnsav2 program.
  193. ;
  194. Multiplex proc far
  195.         cmp     ah,Multiplex_No         ; is this our number?
  196.         je      Mine                    ; yes,...
  197.         jmp     Old_Multiplex           ; no, pass it on.
  198.  
  199. Mine:   cmp     al,Get_Installed_State  ; are we just testing?
  200.         jne     Mine2                   ; work to do
  201.  
  202. ; Set result to indicate installed.  Also, pass back our name as further
  203. ; check for someone else using the number.
  204.         mov     al,0ffh                 ; code to say we're here
  205.         push    ds                      ; copy ds to es
  206.         pop     es                      ; ...
  207.         lea     di,es:Scrnsav_Str       ; offset for our name
  208.         iret                            ; return it to caller.
  209.  
  210. ; Look for other function requests
  211. Mine2:  cmp     al,Scrnsav_Enable
  212.         jne     Mine3
  213.         mov     Disabled,False          ; set enabled
  214.         jmp     Valid
  215.  
  216. Mine3:  cmp     al,Scrnsav_Disable
  217.         jne     Mine4
  218.         mov     Disabled,True           ; set disabled
  219.         jmp     Valid
  220.  
  221. Mine4:  cmp     al,Scrnsav_Set_Interval
  222.         jne     Invalid
  223.         mov     Idle_Max,bx             ; reset interval
  224.  
  225. Valid:  mov     al,0                    ; set success code
  226.         iret
  227.  
  228. Invalid: mov    al,1                    ; r